package framework.graphics;

import javax.microedition.khronos.opengles.GL10;

import framework.managers.TextureManager;

public class TextureRegion extends Texture {
	
	public TextureRegion(String textureName, float x1, float y1, float x2, float y2) {
		FullTexture texture = TextureManager.getTexture(textureName);
		this.textureId = texture.getTextureId();
		this.width = x2 - x1;
		this.height = y2 - y1;
		float texW = texture.getWidth();
		float texH = texture.getHeight();
		float s1 = x1 / texW;
		float t1 = y1 / texH;
		float s2 = x2 / texW;
		float t2 = y2 / texH;
		setVertices(new float[] { 
        		0, 0, s1, t2, 
                0, height, s1, t1, 
                width, height, s2, t1, 
                width, 0, s2, t2 
                });
		setIndices(new short[] { 
        		0, 1, 2, 
                2, 3, 0 
                });
	}
	
	@Override
	public void draw(float deltaTime, GL10 gl, float x, float y) {
		draw(gl, x, y, 0, 0, 0, 1, 1, 0, 0, vertices, indices);
	}

}
